home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: info.physics.utoronto.ca!olivers
- From: olivers@helios.physics.utoronto.ca (Oliver Schonborn)
- Subject: Help: crash when doing fprintf
- Message-ID: <DL74rA.L5v@info.physics.utoronto.ca>
- Nntp-Posting-Host: helios.physics.utoronto.ca
- Sender: news@info.physics.utoronto.ca (System Administrator)
- Organization: University of Toronto - Dept. of Physics
- Date: Mon, 15 Jan 1996 00:16:22 GMT
-
-
- Hello folks!
-
- My program crashes when it executes the following statements:
-
- char frootn[200]=".",
- fout[200] ="";
- float time;
- FILE *fp;
- ....
- sprintf(fout,"%s/test%-.5g",frootn,time);
- printf("Outputting to %s...\n",fout);
- fp=fopen(fout,"w");
- fprintf(fp,"Hello\n");
-
- This is what fp points to at crash time:
-
- 0x40001038 struct FILE {
- __cnt = 0;
- __ptr = 00000000;
- __base = 00000000;
- __flag = 2;
- __fileL = 3;
- __fileH = 0;
- }
-
- It crashes deep inside the fprintf. A trace with the debugger
- indicates where (main called _fprintf which called _wrtchk which
- called _findbuf which called malloc):
-
- 0 malloc@libc + 0x00000470 (0x7b012538, 0x7b011168, 0x7b011164, 0x7b011160)
- 1 _findbuf@libc + 0x000000fc (0x160, 0x8, 0x160, 0x7b0335b0)
- 2 _wrtchk@libc + 0x00000058 (0x40061f40, 0x40061d38, 0x40061938, 0x3f7b53d2)
- 3 _fprintf@libc + 0x00000024 (0x3c23d71a, 0x7b0336e4, 0x7b014e60, 0x7b014e6c)
- 4 main (argc = 3, argv = 0x7b033494) [sfbynorm.c: 556]
-
- I've never seen anything like that bug before. I used gcc 2.7.1
- with -Wall -pedantic and get no warnings whatsoever. With lint the
- only warning I get is a possible pointer alignment problem from the
- 2 lines which define (and initialize) frootn[] and fout[], though I
- don't know whether I should take that seriously.
-
- Anybody have any clue? Thanks for any help,
-
- Oliver
- --
- _________________________________........----------------,
- /\ OliverS@physics.utoronto.ca \
- \_| Condensed-Matter/Quantum-Optics Theory Group )
- / Physics Dept University of Toronto -- Canada /
-